﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace Project
{
    public class Map : Renderable
    {
        protected Model map;

        protected Effect worldEffect;
        protected Texture worldTexture;
        protected Texture bumpTexture;
        protected Texture palateTexture;

        public Map()
        {
        }

        public void load(ContentManager content, string mapName, string textureName,
            string palateTextureName, string bumpTextureName)
        {
            // load the texture
            worldTexture = content.Load<Texture>(textureName);
            palateTexture = content.Load<Texture>(palateTextureName);
            bumpTexture = content.Load<Texture>(bumpTextureName);

            // Load the shader
            worldEffect = content.Load<Effect>("effects/staticmap");
            worldEffect.Parameters["Texture"].SetValue(worldTexture);
            worldEffect.Parameters["PalateTexture"].SetValue(palateTexture);
            worldEffect.Parameters["BumpTexture"].SetValue(bumpTexture);

            // load the map mesh
            map = content.Load<Model>(mapName);
        }

        public void render(GameTime gt, Camera camera)
        {
            worldEffect.Parameters["World"].SetValue(Matrix.Identity);
            worldEffect.Parameters["WVP"].SetValue(camera.view * camera.projection);

            foreach (ModelMesh mesh in map.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    part.Effect = worldEffect;
                }
                mesh.Draw();
            }
        }
    }
}
